// 两数之和
pub fn two_sum(nums: &Vec<i32>, target: i32) -> Vec<i32> {
  use std::collections::HashMap;
  let mut hash: HashMap<i32, i32> = HashMap::new();
  let mut v: Vec<i32> = vec![];
  for i in 0..nums.len() {
    let k: i32 = target - nums[i];
    match hash.get(&k) {
      Some(&val) => {
        v.push(val);
        v.push(i as i32);
        break;
      }
      None => {
        hash.insert(nums[i], i as i32);
        continue;
      }
    }
  }
  v
}

#[test]
fn test_two_sum() {
  let v = vec![2, 7, 11, 15];
  let target = 9;
  assert_eq!(vec![0, 1], two_sum(&v, target));
}
